{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import _pickle as cPickle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_data = cPickle.load(\n",
    "    open('./data1/df_data.pkl','rb')\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 1149772 entries, 0 to 1149771\n",
      "Data columns (total 5 columns):\n",
      " #   Column       Non-Null Count    Dtype \n",
      "---  ------       --------------    ----- \n",
      " 0   user_id      1149772 non-null  int64 \n",
      " 1   location     1149772 non-null  object\n",
      " 2   age          1149772 non-null  int32 \n",
      " 3   item_id      1149772 non-null  object\n",
      " 4   book_rating  1149772 non-null  int32 \n",
      "dtypes: int32(2), int64(1), object(2)\n",
      "memory usage: 43.9+ MB\n"
     ]
    }
   ],
   "source": [
    "df_data.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>location</th>\n",
       "      <th>age</th>\n",
       "      <th>item_id</th>\n",
       "      <th>book_rating</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>usa</td>\n",
       "      <td>3</td>\n",
       "      <td>0195153448</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7</td>\n",
       "      <td>usa</td>\n",
       "      <td>0</td>\n",
       "      <td>034542252</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8</td>\n",
       "      <td>canada</td>\n",
       "      <td>0</td>\n",
       "      <td>0002005018</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>8</td>\n",
       "      <td>canada</td>\n",
       "      <td>0</td>\n",
       "      <td>0060973129</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8</td>\n",
       "      <td>canada</td>\n",
       "      <td>0</td>\n",
       "      <td>0374157065</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   user_id location  age     item_id  book_rating\n",
       "0        2      usa    3  0195153448            0\n",
       "1        7      usa    0   034542252            0\n",
       "2        8   canada    0  0002005018            5\n",
       "3        8   canada    0  0060973129            0\n",
       "4        8   canada    0  0374157065            0"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#random.sample  只支持列表 要把arr转化成list\n",
    "random.seed(123)\n",
    "text_index_s = random.sample(\n",
    "    df_data.index.to_list(),\n",
    "    int(len(df_data)*0.3)\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[109814,\n",
       " 561359,\n",
       " 182843,\n",
       " 854047,\n",
       " 559003,\n",
       " 225863,\n",
       " 80014,\n",
       " 795081,\n",
       " 1124497,\n",
       " 696669,\n",
       " 714705,\n",
       " 108845,\n",
       " 334836,\n",
       " 283236,\n",
       " 707194,\n",
       " 700021,\n",
       " 514144,\n",
       " 343464,\n",
       " 3503,\n",
       " 914936,\n",
       " 183738,\n",
       " 791873,\n",
       " 146542,\n",
       " 13830,\n",
       " 661565,\n",
       " 940198,\n",
       " 213986,\n",
       " 92038,\n",
       " 194541,\n",
       " 298162,\n",
       " 264764,\n",
       " 44535,\n",
       " 611952,\n",
       " 903112,\n",
       " 1000180,\n",
       " 556419,\n",
       " 984178,\n",
       " 77056,\n",
       " 639835,\n",
       " 720292,\n",
       " 1094021,\n",
       " 1012843,\n",
       " 433822,\n",
       " 1105356,\n",
       " 661154,\n",
       " 26315,\n",
       " 835165,\n",
       " 1075319,\n",
       " 910974,\n",
       " 1129357,\n",
       " 1019502,\n",
       " 1091796,\n",
       " 879747,\n",
       " 785428,\n",
       " 1069686,\n",
       " 66776,\n",
       " 380559,\n",
       " 173245,\n",
       " 1021114,\n",
       " 549217,\n",
       " 356781,\n",
       " 702337,\n",
       " 706564,\n",
       " 820391,\n",
       " 153701,\n",
       " 957909,\n",
       " 812972,\n",
       " 704865,\n",
       " 34200,\n",
       " 396491,\n",
       " 184879,\n",
       " 762346,\n",
       " 26904,\n",
       " 738016,\n",
       " 480519,\n",
       " 850854,\n",
       " 1115679,\n",
       " 1050689,\n",
       " 125255,\n",
       " 603355,\n",
       " 1037627,\n",
       " 489419,\n",
       " 1141207,\n",
       " 1014626,\n",
       " 372432,\n",
       " 322461,\n",
       " 1124870,\n",
       " 932183,\n",
       " 793961,\n",
       " 967407,\n",
       " 92547,\n",
       " 21290,\n",
       " 282544,\n",
       " 957015,\n",
       " 405121,\n",
       " 44058,\n",
       " 537630,\n",
       " 738297,\n",
       " 570278,\n",
       " 910727,\n",
       " 881553,\n",
       " 745,\n",
       " 227794,\n",
       " 131300,\n",
       " 1070219,\n",
       " 744617,\n",
       " 186203,\n",
       " 173865,\n",
       " 908486,\n",
       " 17954,\n",
       " 1123656,\n",
       " 791588,\n",
       " 154107,\n",
       " 1146267,\n",
       " 847684,\n",
       " 61104,\n",
       " 676243,\n",
       " 550586,\n",
       " 990926,\n",
       " 69271,\n",
       " 702190,\n",
       " 868371,\n",
       " 730578,\n",
       " 49895,\n",
       " 343636,\n",
       " 878786,\n",
       " 134734,\n",
       " 301956,\n",
       " 780370,\n",
       " 492754,\n",
       " 164367,\n",
       " 119871,\n",
       " 1087784,\n",
       " 812035,\n",
       " 1127295,\n",
       " 642071,\n",
       " 306476,\n",
       " 610679,\n",
       " 816335,\n",
       " 772775,\n",
       " 265226,\n",
       " 1121809,\n",
       " 708259,\n",
       " 1084444,\n",
       " 250748,\n",
       " 349808,\n",
       " 810016,\n",
       " 906351,\n",
       " 130140,\n",
       " 285245,\n",
       " 953660,\n",
       " 43227,\n",
       " 733037,\n",
       " 943139,\n",
       " 946127,\n",
       " 637126,\n",
       " 899696,\n",
       " 59261,\n",
       " 332560,\n",
       " 1093855,\n",
       " 681273,\n",
       " 1083897,\n",
       " 1079444,\n",
       " 288088,\n",
       " 720520,\n",
       " 1048832,\n",
       " 219734,\n",
       " 1143907,\n",
       " 773850,\n",
       " 471658,\n",
       " 713201,\n",
       " 194735,\n",
       " 569903,\n",
       " 1061791,\n",
       " 510109,\n",
       " 426292,\n",
       " 675402,\n",
       " 554798,\n",
       " 835023,\n",
       " 90229,\n",
       " 1049723,\n",
       " 168530,\n",
       " 413337,\n",
       " 1059336,\n",
       " 418380,\n",
       " 35987,\n",
       " 407189,\n",
       " 562560,\n",
       " 484291,\n",
       " 178467,\n",
       " 664856,\n",
       " 175617,\n",
       " 715431,\n",
       " 1127600,\n",
       " 279901,\n",
       " 1120263,\n",
       " 284050,\n",
       " 1014935,\n",
       " 1032400,\n",
       " 835413,\n",
       " 59191,\n",
       " 538657,\n",
       " 1019467,\n",
       " 714125,\n",
       " 830080,\n",
       " 470076,\n",
       " 1051213,\n",
       " 264463,\n",
       " 12500,\n",
       " 1036988,\n",
       " 720150,\n",
       " 256515,\n",
       " 109964,\n",
       " 756328,\n",
       " 966286,\n",
       " 758835,\n",
       " 882401,\n",
       " 661665,\n",
       " 752186,\n",
       " 454231,\n",
       " 941719,\n",
       " 719392,\n",
       " 403639,\n",
       " 378905,\n",
       " 801897,\n",
       " 130950,\n",
       " 869746,\n",
       " 787134,\n",
       " 1049571,\n",
       " 556750,\n",
       " 366747,\n",
       " 789377,\n",
       " 772836,\n",
       " 145037,\n",
       " 620545,\n",
       " 256537,\n",
       " 556617,\n",
       " 1054510,\n",
       " 675773,\n",
       " 115157,\n",
       " 798144,\n",
       " 108221,\n",
       " 814571,\n",
       " 626029,\n",
       " 225372,\n",
       " 976325,\n",
       " 680935,\n",
       " 508920,\n",
       " 934119,\n",
       " 557662,\n",
       " 921114,\n",
       " 721532,\n",
       " 520960,\n",
       " 955223,\n",
       " 1050664,\n",
       " 576761,\n",
       " 707114,\n",
       " 102275,\n",
       " 382113,\n",
       " 258661,\n",
       " 41758,\n",
       " 897832,\n",
       " 1041148,\n",
       " 276592,\n",
       " 1001016,\n",
       " 1122197,\n",
       " 89674,\n",
       " 986307,\n",
       " 1136472,\n",
       " 296855,\n",
       " 683338,\n",
       " 775486,\n",
       " 463170,\n",
       " 67431,\n",
       " 971833,\n",
       " 1057208,\n",
       " 605469,\n",
       " 29229,\n",
       " 672395,\n",
       " 810551,\n",
       " 477263,\n",
       " 131356,\n",
       " 531338,\n",
       " 597882,\n",
       " 352364,\n",
       " 872534,\n",
       " 749995,\n",
       " 891240,\n",
       " 91029,\n",
       " 27200,\n",
       " 1041885,\n",
       " 345546,\n",
       " 415741,\n",
       " 97771,\n",
       " 565077,\n",
       " 1100527,\n",
       " 347977,\n",
       " 1114073,\n",
       " 406967,\n",
       " 634918,\n",
       " 1048237,\n",
       " 980191,\n",
       " 470048,\n",
       " 592334,\n",
       " 1106898,\n",
       " 193270,\n",
       " 216484,\n",
       " 928435,\n",
       " 1142866,\n",
       " 585733,\n",
       " 409571,\n",
       " 1092000,\n",
       " 142134,\n",
       " 822887,\n",
       " 852309,\n",
       " 940689,\n",
       " 232674,\n",
       " 126147,\n",
       " 907352,\n",
       " 914382,\n",
       " 1084838,\n",
       " 747563,\n",
       " 322642,\n",
       " 1034354,\n",
       " 282193,\n",
       " 407811,\n",
       " 443820,\n",
       " 506066,\n",
       " 78762,\n",
       " 512709,\n",
       " 436574,\n",
       " 154014,\n",
       " 846516,\n",
       " 54238,\n",
       " 22976,\n",
       " 864494,\n",
       " 675113,\n",
       " 1146990,\n",
       " 62809,\n",
       " 87748,\n",
       " 517014,\n",
       " 913653,\n",
       " 611074,\n",
       " 389919,\n",
       " 637921,\n",
       " 236389,\n",
       " 592546,\n",
       " 681184,\n",
       " 444619,\n",
       " 1081071,\n",
       " 54455,\n",
       " 758189,\n",
       " 320601,\n",
       " 977053,\n",
       " 471720,\n",
       " 868825,\n",
       " 465671,\n",
       " 1070707,\n",
       " 911428,\n",
       " 819301,\n",
       " 396273,\n",
       " 818071,\n",
       " 161624,\n",
       " 1042144,\n",
       " 89327,\n",
       " 601433,\n",
       " 291971,\n",
       " 997501,\n",
       " 224059,\n",
       " 264196,\n",
       " 255861,\n",
       " 964908,\n",
       " 740050,\n",
       " 36537,\n",
       " 933298,\n",
       " 1092348,\n",
       " 740307,\n",
       " 605566,\n",
       " 760831,\n",
       " 447476,\n",
       " 819118,\n",
       " 99059,\n",
       " 221725,\n",
       " 1066443,\n",
       " 198929,\n",
       " 681289,\n",
       " 173582,\n",
       " 431910,\n",
       " 805900,\n",
       " 377060,\n",
       " 878265,\n",
       " 264549,\n",
       " 996491,\n",
       " 294801,\n",
       " 11146,\n",
       " 340925,\n",
       " 180998,\n",
       " 694210,\n",
       " 67719,\n",
       " 205964,\n",
       " 307042,\n",
       " 459429,\n",
       " 959669,\n",
       " 902206,\n",
       " 421152,\n",
       " 848645,\n",
       " 125043,\n",
       " 118215,\n",
       " 318132,\n",
       " 239885,\n",
       " 967488,\n",
       " 189346,\n",
       " 281709,\n",
       " 86357,\n",
       " 752736,\n",
       " 921644,\n",
       " 432745,\n",
       " 501516,\n",
       " 493109,\n",
       " 904503,\n",
       " 716087,\n",
       " 299906,\n",
       " 187491,\n",
       " 20009,\n",
       " 611709,\n",
       " 686569,\n",
       " 840353,\n",
       " 724681,\n",
       " 480043,\n",
       " 127664,\n",
       " 121540,\n",
       " 135482,\n",
       " 231375,\n",
       " 523609,\n",
       " 604122,\n",
       " 491725,\n",
       " 262383,\n",
       " 1687,\n",
       " 1139035,\n",
       " 552101,\n",
       " 882632,\n",
       " 771216,\n",
       " 777227,\n",
       " 273156,\n",
       " 874231,\n",
       " 69671,\n",
       " 606766,\n",
       " 733699,\n",
       " 657401,\n",
       " 6892,\n",
       " 735140,\n",
       " 1061919,\n",
       " 6079,\n",
       " 616845,\n",
       " 167530,\n",
       " 793819,\n",
       " 385169,\n",
       " 682915,\n",
       " 932641,\n",
       " 219400,\n",
       " 1119979,\n",
       " 416757,\n",
       " 836914,\n",
       " 148076,\n",
       " 401981,\n",
       " 430634,\n",
       " 751340,\n",
       " 896262,\n",
       " 1008449,\n",
       " 594122,\n",
       " 1142270,\n",
       " 342581,\n",
       " 812204,\n",
       " 56025,\n",
       " 546023,\n",
       " 65258,\n",
       " 338387,\n",
       " 404069,\n",
       " 766551,\n",
       " 385881,\n",
       " 211420,\n",
       " 286015,\n",
       " 212640,\n",
       " 567175,\n",
       " 254291,\n",
       " 154333,\n",
       " 757303,\n",
       " 119078,\n",
       " 534461,\n",
       " 757390,\n",
       " 272820,\n",
       " 528632,\n",
       " 861400,\n",
       " 194544,\n",
       " 545223,\n",
       " 1089301,\n",
       " 250353,\n",
       " 1121839,\n",
       " 253657,\n",
       " 691618,\n",
       " 601670,\n",
       " 646787,\n",
       " 921714,\n",
       " 492782,\n",
       " 11221,\n",
       " 196228,\n",
       " 237492,\n",
       " 211657,\n",
       " 924725,\n",
       " 814234,\n",
       " 752392,\n",
       " 378105,\n",
       " 277462,\n",
       " 812471,\n",
       " 730,\n",
       " 871071,\n",
       " 439680,\n",
       " 503279,\n",
       " 8960,\n",
       " 874948,\n",
       " 271879,\n",
       " 175857,\n",
       " 366271,\n",
       " 1124340,\n",
       " 559272,\n",
       " 883535,\n",
       " 352631,\n",
       " 818167,\n",
       " 640838,\n",
       " 136144,\n",
       " 49969,\n",
       " 255885,\n",
       " 825624,\n",
       " 558081,\n",
       " 112323,\n",
       " 1140006,\n",
       " 394254,\n",
       " 650814,\n",
       " 653065,\n",
       " 1147987,\n",
       " 709294,\n",
       " 47523,\n",
       " 304645,\n",
       " 646161,\n",
       " 597447,\n",
       " 419355,\n",
       " 895433,\n",
       " 444527,\n",
       " 1043320,\n",
       " 94302,\n",
       " 886512,\n",
       " 137703,\n",
       " 322871,\n",
       " 356838,\n",
       " 99285,\n",
       " 466357,\n",
       " 131556,\n",
       " 941570,\n",
       " 398080,\n",
       " 840368,\n",
       " 910220,\n",
       " 1121554,\n",
       " 765728,\n",
       " 156459,\n",
       " 453377,\n",
       " 188095,\n",
       " 921317,\n",
       " 89614,\n",
       " 1121836,\n",
       " 653176,\n",
       " 65505,\n",
       " 436695,\n",
       " 74733,\n",
       " 327544,\n",
       " 1101688,\n",
       " 206803,\n",
       " 106452,\n",
       " 863570,\n",
       " 990900,\n",
       " 806012,\n",
       " 699942,\n",
       " 382605,\n",
       " 848726,\n",
       " 898912,\n",
       " 217962,\n",
       " 183103,\n",
       " 91237,\n",
       " 452969,\n",
       " 319263,\n",
       " 285083,\n",
       " 633261,\n",
       " 765021,\n",
       " 1069771,\n",
       " 882484,\n",
       " 551957,\n",
       " 594903,\n",
       " 861875,\n",
       " 385935,\n",
       " 1118852,\n",
       " 1109686,\n",
       " 192149,\n",
       " 4978,\n",
       " 302044,\n",
       " 1089983,\n",
       " 212087,\n",
       " 952204,\n",
       " 516509,\n",
       " 1005376,\n",
       " 61762,\n",
       " 779435,\n",
       " 621299,\n",
       " 976012,\n",
       " 783233,\n",
       " 596045,\n",
       " 1129327,\n",
       " 710147,\n",
       " 416666,\n",
       " 354801,\n",
       " 83209,\n",
       " 786209,\n",
       " 109864,\n",
       " 203064,\n",
       " 1029344,\n",
       " 781087,\n",
       " 883687,\n",
       " 371620,\n",
       " 219616,\n",
       " 152751,\n",
       " 485551,\n",
       " 804665,\n",
       " 284784,\n",
       " 1062166,\n",
       " 208527,\n",
       " 1023643,\n",
       " 1102436,\n",
       " 485971,\n",
       " 1101458,\n",
       " 1043396,\n",
       " 703065,\n",
       " 661239,\n",
       " 872957,\n",
       " 560817,\n",
       " 708507,\n",
       " 1008496,\n",
       " 370053,\n",
       " 493413,\n",
       " 214148,\n",
       " 110598,\n",
       " 1081654,\n",
       " 301385,\n",
       " 773880,\n",
       " 84976,\n",
       " 294237,\n",
       " 308638,\n",
       " 350728,\n",
       " 837626,\n",
       " 375029,\n",
       " 522242,\n",
       " 1066677,\n",
       " 383039,\n",
       " 1019013,\n",
       " 1048855,\n",
       " 10991,\n",
       " 986913,\n",
       " 326666,\n",
       " 580262,\n",
       " 734385,\n",
       " 1058912,\n",
       " 920159,\n",
       " 471446,\n",
       " 140275,\n",
       " 895225,\n",
       " 990655,\n",
       " 831120,\n",
       " 668110,\n",
       " 99155,\n",
       " 900474,\n",
       " 873334,\n",
       " 185073,\n",
       " 686426,\n",
       " 929899,\n",
       " 972748,\n",
       " 30341,\n",
       " 234151,\n",
       " 79704,\n",
       " 739630,\n",
       " 765748,\n",
       " 671750,\n",
       " 499782,\n",
       " 1149754,\n",
       " 998463,\n",
       " 715449,\n",
       " 489815,\n",
       " 68495,\n",
       " 387247,\n",
       " 265647,\n",
       " 941170,\n",
       " 424322,\n",
       " 983346,\n",
       " 898770,\n",
       " 29876,\n",
       " 730205,\n",
       " 262216,\n",
       " 564486,\n",
       " 747551,\n",
       " 1141674,\n",
       " 651711,\n",
       " 149932,\n",
       " 725600,\n",
       " 431650,\n",
       " 98373,\n",
       " 247675,\n",
       " 269563,\n",
       " 1084426,\n",
       " 21081,\n",
       " 1019358,\n",
       " 1080897,\n",
       " 881715,\n",
       " 838210,\n",
       " 1047647,\n",
       " 134457,\n",
       " 395178,\n",
       " 384724,\n",
       " 732095,\n",
       " 480006,\n",
       " 690151,\n",
       " 869687,\n",
       " 1024044,\n",
       " 245292,\n",
       " 830302,\n",
       " 153605,\n",
       " 753034,\n",
       " 1068851,\n",
       " 787618,\n",
       " 214983,\n",
       " 410952,\n",
       " 539302,\n",
       " 187985,\n",
       " 253860,\n",
       " 772147,\n",
       " 366816,\n",
       " 398503,\n",
       " 172810,\n",
       " 137151,\n",
       " 885524,\n",
       " 940566,\n",
       " 915974,\n",
       " 938218,\n",
       " 84673,\n",
       " 869504,\n",
       " 108104,\n",
       " 196960,\n",
       " 627310,\n",
       " 1064306,\n",
       " 823297,\n",
       " 789417,\n",
       " 696949,\n",
       " 771291,\n",
       " 732272,\n",
       " 132346,\n",
       " 698591,\n",
       " 388873,\n",
       " 253950,\n",
       " 56545,\n",
       " 931959,\n",
       " 821739,\n",
       " 1048758,\n",
       " 673920,\n",
       " 69142,\n",
       " 429117,\n",
       " 601889,\n",
       " 662863,\n",
       " 602012,\n",
       " 318152,\n",
       " 670651,\n",
       " 989202,\n",
       " 756439,\n",
       " 474776,\n",
       " 1120703,\n",
       " 72267,\n",
       " 987566,\n",
       " 326563,\n",
       " 436186,\n",
       " 692428,\n",
       " 504832,\n",
       " 997963,\n",
       " 464807,\n",
       " 654636,\n",
       " 341123,\n",
       " 412899,\n",
       " 972134,\n",
       " 1011474,\n",
       " 693777,\n",
       " 998308,\n",
       " 937273,\n",
       " 971488,\n",
       " 565547,\n",
       " 915108,\n",
       " 615375,\n",
       " 166356,\n",
       " 825550,\n",
       " 977247,\n",
       " 206661,\n",
       " 675497,\n",
       " 802724,\n",
       " 1112313,\n",
       " 271197,\n",
       " 488947,\n",
       " 120296,\n",
       " 337667,\n",
       " 872923,\n",
       " 1067939,\n",
       " 931441,\n",
       " 571915,\n",
       " 492963,\n",
       " 609368,\n",
       " 366935,\n",
       " 1091089,\n",
       " 497956,\n",
       " 875022,\n",
       " 173847,\n",
       " 808617,\n",
       " 1148637,\n",
       " 132492,\n",
       " 772276,\n",
       " 976831,\n",
       " 282847,\n",
       " 352816,\n",
       " 722030,\n",
       " 269181,\n",
       " 293044,\n",
       " 638183,\n",
       " 872316,\n",
       " 323973,\n",
       " 336192,\n",
       " 952491,\n",
       " 562512,\n",
       " 486553,\n",
       " 411430,\n",
       " 622232,\n",
       " 401121,\n",
       " 103150,\n",
       " 648223,\n",
       " 402254,\n",
       " 938155,\n",
       " 53999,\n",
       " 379389,\n",
       " 332318,\n",
       " 698432,\n",
       " 338213,\n",
       " 683223,\n",
       " 82865,\n",
       " 210899,\n",
       " 510396,\n",
       " 86585,\n",
       " 728612,\n",
       " 451989,\n",
       " 175258,\n",
       " 366484,\n",
       " 968530,\n",
       " 912529,\n",
       " 360797,\n",
       " 198188,\n",
       " 1099292,\n",
       " 106377,\n",
       " 497123,\n",
       " 213959,\n",
       " 869164,\n",
       " 326679,\n",
       " 498099,\n",
       " 643532,\n",
       " 358249,\n",
       " 944903,\n",
       " 268112,\n",
       " 773413,\n",
       " 838469,\n",
       " 47282,\n",
       " 1022339,\n",
       " 652032,\n",
       " 908495,\n",
       " 905702,\n",
       " 334966,\n",
       " 301381,\n",
       " 403577,\n",
       " 479885,\n",
       " 627810,\n",
       " 924923,\n",
       " 1060676,\n",
       " 306722,\n",
       " 413855,\n",
       " 333149,\n",
       " 1110303,\n",
       " 353721,\n",
       " 487363,\n",
       " 1045670,\n",
       " 248936,\n",
       " 198066,\n",
       " 634702,\n",
       " 371650,\n",
       " 34206,\n",
       " 1046159,\n",
       " 849686,\n",
       " 485076,\n",
       " 485994,\n",
       " 905554,\n",
       " 163568,\n",
       " 562565,\n",
       " 527432,\n",
       " 623014,\n",
       " 557870,\n",
       " 495074,\n",
       " 317657,\n",
       " 428469,\n",
       " 398744,\n",
       " 18562,\n",
       " 189848,\n",
       " 859949,\n",
       " 1075705,\n",
       " 634375,\n",
       " 1023988,\n",
       " 148905,\n",
       " 389049,\n",
       " 974997,\n",
       " 677793,\n",
       " 1058551,\n",
       " 151076,\n",
       " 914491,\n",
       " 1141980,\n",
       " 650380,\n",
       " 201003,\n",
       " 945582,\n",
       " 51170,\n",
       " 296587,\n",
       " 555883,\n",
       " 700745,\n",
       " 266862,\n",
       " 924954,\n",
       " 980983,\n",
       " 634185,\n",
       " 244015,\n",
       " 1038214,\n",
       " 1006276,\n",
       " 735650,\n",
       " 781706,\n",
       " 260931,\n",
       " 483990,\n",
       " 751646,\n",
       " 533716,\n",
       " 560773,\n",
       " 1105305,\n",
       " 193499,\n",
       " 217048,\n",
       " 19277,\n",
       " 727195,\n",
       " 784726,\n",
       " 944158,\n",
       " 938337,\n",
       " 812435,\n",
       " 315791,\n",
       " 374101,\n",
       " 503888,\n",
       " 376309,\n",
       " 696965,\n",
       " 434083,\n",
       " 950254,\n",
       " 301236,\n",
       " 511392,\n",
       " 898230,\n",
       " 779934,\n",
       " 791880,\n",
       " 337612,\n",
       " 541850,\n",
       " 768051,\n",
       " 829422,\n",
       " 1121091,\n",
       " 907689,\n",
       " 11869,\n",
       " 484354,\n",
       " 995680,\n",
       " 472817,\n",
       " 481443,\n",
       " 324567,\n",
       " 721185,\n",
       " 932828,\n",
       " 671763,\n",
       " 7845,\n",
       " 977803,\n",
       " 706265,\n",
       " 952390,\n",
       " 113574,\n",
       " 497935,\n",
       " 47926,\n",
       " 544254,\n",
       " 279500,\n",
       " 568045,\n",
       " 382396,\n",
       " 1030814,\n",
       " 382315,\n",
       " 333850,\n",
       " 507412,\n",
       " ...]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text_index_s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>location</th>\n",
       "      <th>age</th>\n",
       "      <th>item_id</th>\n",
       "      <th>book_rating</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>109814</th>\n",
       "      <td>27462</td>\n",
       "      <td>usa</td>\n",
       "      <td>0</td>\n",
       "      <td>1587492695</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>561359</th>\n",
       "      <td>137190</td>\n",
       "      <td>france</td>\n",
       "      <td>3</td>\n",
       "      <td>0552997234</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>182843</th>\n",
       "      <td>42721</td>\n",
       "      <td>canada</td>\n",
       "      <td>3</td>\n",
       "      <td>0671024108</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>854047</th>\n",
       "      <td>208829</td>\n",
       "      <td>canada</td>\n",
       "      <td>0</td>\n",
       "      <td>0140503897</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>559003</th>\n",
       "      <td>136348</td>\n",
       "      <td>usa</td>\n",
       "      <td>4</td>\n",
       "      <td>0807220299</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        user_id location  age     item_id  book_rating\n",
       "109814    27462      usa    0  1587492695            0\n",
       "561359   137190   france    3  0552997234            8\n",
       "182843    42721   canada    3  0671024108            8\n",
       "854047   208829   canada    0  0140503897            0\n",
       "559003   136348      usa    4  0807220299            9"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 有了index后  根据index 把索引对应到具体的数据\n",
    "df_data_text = df_data.loc[\n",
    "    text_index_s\n",
    "]\n",
    "df_data_text.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_data_train = df_data[\n",
    "    ~df_data.index.isin(text_index_s)\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "cPickle.dump(\n",
    "    df_data_text,\n",
    "    open('./data1/df_data_text.pkl','wb')\n",
    ")\n",
    "cPickle.dump(\n",
    "    df_data_train,\n",
    "    open('./data1/df_data_training.pkl','wb')\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
